<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>产品列表</title>
    <link rel="stylesheet" href="css/font-awesome.min.css"/>
    <link rel="stylesheet" href="css/font-awesome-ie7.min.css"/>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <link href="css/jquery.datetimepicker.css" rel="stylesheet">
    <link rel="stylesheet" href="css/admin.css"/>

    <link rel="stylesheet" type="text/css" href="css/paging.css">

    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <![endif]-->
    <!--[if lt IE 10]>
    <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/jquery-placeholder/2.0.8/jquery.placeholder.min.js"></script>
    <![endif]-->
</head>
<body>
<div id="gray_bg"></div>

<!-- 上下架开始 -->
<div id="deleteDiadog" class="diadog">
    <div class="diadog-tit">
        <div class="row">
            <div class="col-md-11"><span id="delTitle">确定下架该档案？</span></div>
            <div class="col-md-1 close"><span>×</span></div>
        </div>
    </div>
    <div class="diadog-con" style="padding:30px 0">

        <div class="form-horizontal" role="form">
            <div class="row">
                <div class="col-md-12"></div>

                <div class="form-group" style="text-align: center;">
                    <div class="col-md-1"></div>
                    <div class="col-md-2">
                        <button id="enableSure" type="submit" class="btn btn-primary">确 定</button>
                        <button id="flagSure" type="submit" class="btn btn-primary">确 定</button>
                    </div>
                    <div class="col-md-2">
                        <button id="btn-default" type="submit" class="btn btn-default">取 消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 上下架结束 -->
<!-- header start -->
<div id="header" class="header">

</div>
<!-- header end -->
<!-- usercenter start -->
<div class="usercotent">
    <div id="center-left"></div>
    <div class="usercotentr floatr">
        <div class="user-tit" style="margin-bottom:10px">
            <h3>产品档案列表</h3>
        </div>
        <div class="usercotent-con">
            <div class="col-md-2" style="width: 140px !important;">
                <input id="search_keyvalue" class="inputStory" type="text"
                       style="width:140px !important;height: 34px !important;" placeholder="关键字">
            </div>
            <div class="col-md-1">
                <button id="order_search" type="button" class="btn btn-success">查询</button>
            </div>
            <!--<div class="col-md-12">-->
            <!--<a href="product-bigType.html">产品大类</a>-->
            <!--&gt;-->
            <!--<a id="smtypeName"></a>-->
            <!--&gt;-->
            <!--<a id="infoName"></a>-->
            <!--&gt;-->
            <!--&lt;!&ndash;<button onclick="history.go(-1)" type="button" class="btn btn-danger pull-right">返回上一级</button>&ndash;&gt;-->
            <!--<button id="addCategory" type="button" class="btn btn-danger pull-right">添加档案</button>-->
            <!--</div>-->


            <div class="down">
                <table id="testMyGrid" class="table table-bordered table-hover"></table>
            </div>
            <!-- page start -->
            <nav class="totalpage floatr">
                <span>总共</span><strong id="totalpage"></strong><span>条</span>
                <div id="pageTool" style="margin-top:20px;"></div>
            </nav>
            <div class="clear"></div>
            <!-- page end -->
        </div>

    </div>
    <div class="clear"></div>
</div>

<!-- usercenter end -->

<!-- footer start -->
<div class="footer">
    <div class="bot">
        <p style="padding-top: 10px; text-align: center">Copyright (C) 都能印 2014-2016, all Rights Reserved |
            豫ICP备14024464号-1 | 增值电信业务经营许可证：豫B2-20150019</p>
        <p class="authentication" style="padding-bottom: 10px; padding-top: 10px;">
            <img src="img/footer1.png" alt="">
            <img src="img/footer2.png" alt="">
            <img src="img/footer3.png" alt="">
            <img src="img/footer4.png" alt="">
            <img src="img/footer5.png" alt="">
        </p>
    </div>
</div>
<!-- footer end -->
<script src="js/jquery.min-1-11-3.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/widget/myDataGrid.js"></script>
<script src="js/widget/admin.js"></script>
<script type="text/javascript" src="js/query.js"></script>
<script type="text/javascript" src="js/paging.js"></script>
<script type="text/javascript" src="bower_components/plupload/js/plupload.full.min.js"></script>
<script type="text/javascript" src="js/ui.js"></script>
<script type="text/javascript" src="js/qiniu.min.js"></script>
<script type="text/javascript" src="js/upload.js"></script>
<script type="text/javascript">
    var id;
    //开始
    $(function () {
        initSideAccMenu("产品管理", "产品列表");
//        获取数据
//        var dataArray = [
//            {attribute: 'keyWord', attributeValue: "纸抽"}
//        ]
        $("#testMyGrid").grid({
            id: "testMyGrid",
            pageTotalId: "totalpage",
            pageToolId: "pageTool",
            url: "apis/product/getproductlistbyquery",
            columns: [
                {field: 'idOrder', title: '#', conmethod: 'getRecordIndex', calcfield: '', kind: '', region: 0},
                {field: 'partnerCompanyName',title: '企业名称',conmethod: 'getNullStr',calcfield: '',kind: '',region: 0},
                {field: 'bigTypeName', title: '大类名称', conmethod: 'getNullStr', calcfield: '', kind: '', region: 0},
                {field: 'smallTypeName', title: '小类名称', conmethod: 'getNullStr', calcfield: '', kind: '', region: 0},
                {field: 'productName', title: '产品名称', conmethod: 'getNullStr', calcfield: '', kind: '', region: 0},
                {field: 'icon', title: '产品图片', conmethod: 'getIcon', calcfield: '', kind: '', region: 1},
                {field: 'opt', title: '操作', conmethod: 'getUserOptURL', calcfield: '', kind: '', region: 1}
            ],
//            InitializationData: dataArray,
            pagesize: 10
        });


    });

    //  获取图标
    function getIcon() {
        var user = arguments[1];
        var shtml = "";
        if(user.icon == null || user.icon == ""){
            shtml = "<img style='width: 80px;height: 80px'>"
        }else{
            shtml += "<img src='" + user.icon + "' style='width: 80px;height: 80px'>"
        }
        return shtml;
    }
    //    操作
    function getUserOptURL() {
        var user = arguments[1];
        var shtml = "";
        $("#infoName").html(user.smallTypeName);
        if (user.enable == 1) {
            shtml += "<a href=\"javascript:;\" style='color: red'>上架中</a>";
            shtml += "&nbsp&nbsp&nbsp";
            shtml += "<a onclick=\"toEnable(" + user.id + ",0)\"" + " href=\"javascript:;\">点击下架</a>";
        } else {
            shtml += "<a href=\"javascript:;\" style='color: blue'>已下架</a>";
            shtml += "&nbsp&nbsp&nbsp";
            shtml += "<a onclick=\"toEnable(" + user.id + ",1)\"" + " href=\"javascript:;\">点击上架</a>";
        }
        return shtml;
    }

    //    禁用
    var enable;
    function toEnable(id, e) {
        infoId = id;
        enable = e;
        $("#gray_bg").show();
        $("#gray_bg").css({"height": $(document).height()});
        $("#deleteDiadog").show();
        $("#deleteDiadog").center();
        $("#enableSure").show();
        $("#flagSure").hide();
        if (e == 1) {
            $("#delTitle").html("确定上架该档案？");
        } else {
            $("#delTitle").html("确定下架该档案？");
        }
    }
    $("#enableSure").click(function () {
        var data = {
            id: infoId,
            enable: enable
        };
        var url = "apis/product/updateproductinfoenable";
        $.ajax({
            url: url,
            type: 'post',
            data: {
                "productInfo": JSON.stringify(data)
            },
            dataType: 'json',
            success: function (data, status, xhr) {
                if (data.httpCode == 200) {
                    $("#gray_bg").hide();
                    $("#deleteDiadog").hide();
                    window.location.reload();
                } else {
                    alert(data.msg);
                }
            }
        });
    })

        $("#order_search").click(function () {
            var data = getSearchData();
            if (data == null) {
                alert("请输入关键字进行查询");
                return;
            }
            //console.log(data);
            $("#testMyGrid").grid("search", data);
        })
        function getSearchData() {
            var keyWord = $.trim($("#search_keyvalue").val());

            if (keyWord == "" || !keyWord ) {
                var data = null;
            } else {
                var data= {
                    "keyWord":keyWord
                }
            }
            return data;
        }
    //  垂直居中
    jQuery.fn.center = function () {
        this.css("position", "absolute");
        this.css("top", ( $(window).height() - this.height() ) / 2 + $(window).scrollTop() + "px");
        this.css("left", ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() + "px");
        return this;
    }
    $(".close,#btn-default").click(function () {
        $("#gray_bg").hide();
        $("#editDiadog").hide();
        $("#deleteDiadog").hide();

        $("#productName").val("");
        $("#avatar").val("");
        $("#description").val("");
        $("#remark").val("");
        $("#imgName").removeAttr("src");
    })
</script>
</body>
</html>